package com.ruoyi.project.configureSystem.controller;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.framework.tree.TreeUtils;
import com.ruoyi.project.configureSystem.domain.SysNode;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.configureSystem.domain.CStation;
import com.ruoyi.project.configureSystem.service.ICStationService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 站点信息Controller
 *
 * @author wangshuo
 * @date 2021-04-12
 */
@RestController
@RequestMapping("/configureSystem/station")
public class CStationController extends BaseController
{
    @Autowired
    private ICStationService cStationService;
    @Autowired
    private TreeUtils treeUtils;

    /**
     * 查询站点信息列表
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:station:list')")
    @GetMapping("/list")
    public TableDataInfo list(CStation cStation)
    {
        startPage();
        List<CStation> list = cStationService.selectCStationList(cStation);
        return getDataTable(list);
    }

    /**
     * 导出站点信息列表
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:station:export')")
    @Log(title = "站点信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CStation cStation)
    {
        List<CStation> list = cStationService.selectCStationList(cStation);
        ExcelUtil<CStation> util = new ExcelUtil<CStation>(CStation.class);
        return util.exportExcel(list, "station");
    }

    /**
     * 获取站点信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:station:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(cStationService.selectCStationById(id));
    }

    /**
     * 新增站点信息
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:station:add')")
    @Log(title = "站点信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CStation cStation)
    {
        return toAjax(cStationService.insertCStation(cStation));
    }

    /**
     * 修改站点信息
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:station:edit')")
    @Log(title = "站点信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CStation cStation)
    {
        return toAjax(cStationService.updateCStation(cStation));
    }

    /**
     * 删除站点信息
     */
    @PreAuthorize("@ss.hasPermi('configureSystem:station:remove')")
    @Log(title = "站点信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(cStationService.deleteCStationByIds(ids));
    }

    /**
     * 公司-区域-站点树
     */
    @GetMapping("/stationTree")
    public AjaxResult stationTree(CStation cStation)
    {
        List<SysNode> sysNodes = cStationService.stationTree(cStation);
        return AjaxResult.success(treeUtils.buildTreeSelect(sysNodes));
    }
}
